package recover

import (
	"geekbang-go-homework/week04/pkg/middleware"
	"net/http"
)

func Recover() middleware.HandlerFunc {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
			defer func() {
				if err := recover(); err != nil {
					// 错误处理
				}
			}()
			h.ServeHTTP(writer, request)
		})
	}
}
